from comman.activator import *
from comman.layers import *
from comman.net import Sequential
from comman.optimizers import *
from dataset.mnist.mnist import load_mnist

epochs = 20
batch_size = 100
learning_rate = 1e-1

# 读入数据
(x_train, t_train), (x_test, t_test) = load_mnist(one_hot_label=True)
x_validation, t_validation = x_test[:1000], t_test[:1000]
# x_test, t_test = x_test[batch_size:], t_test[batch_size:]

net = Sequential([
    Dense(200, Relu()),
    BatchNormalization(),
    Dense(100, Relu()),
    BatchNormalization(),
    Dense(10, None),
])

net.compile(SoftmaxWithLoss(), SGD(learning_rate))

net.fit(x_train, t_train, epochs=epochs, batch_size=batch_size,
        validation_data=(x_validation, t_validation))

accuracy = net.evaluate(x_test, t_test)
print(f"accuracy={accuracy}")
